//
//  WQDeviceStatusCollectionCell.m
//  WisdomQuestor
//
//  Created by 纪景城 on 2024/12/18.
//

#import "WQDeviceStatusCollectionCell.h"

@implementation WQDeviceStatusCollectionCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubviews:[NSArray arrayWithObjects:self.colorBackImageView, nil]];
        [self.colorBackImageView addSubviews:[NSArray arrayWithObjects:self.deviceTypeImageView, self.roomNameLabel, self.deviceNicenameLabel, self.switchStatusImageView, nil]];
        [self fragmentUI_ViewSet];
    }
    return self;
}

- (void)updateUIWithModel:(ThingSmartDeviceModel *)deviceModel {
    
    [self.deviceTypeImageView ts_loadUrlString:deviceModel.iconUrl];
    
    self.deviceNicenameLabel.text = deviceModel.name;
    
//    self.roomNameLabel.text = deviceModel.roomId;
    
    if (deviceModel.isOnline == YES) {
        
    } else {
        
    }
    
    self.switchStatusImageView.hidden = YES;
    switch (deviceModel.deviceType) {
        case ThingSmartDeviceModelTypeZigbeeSubDev:
        {
            DEBUGLOG(@"开关");
            self.switchStatusImageView.hidden = NO;
        }
            break;
            
        default:
            break;
    }
    
}

#pragma mark ------- Lazy Methods -------

- (void)fragmentUI_ViewSet {
    [self.colorBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    [self.deviceTypeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(kFragmemtFloat(9));
        make.top.equalTo(self.contentView.mas_top).offset(kFragmemtFloat(6));
        make.size.mas_equalTo(kSizzleKapadate(62, 62));
    }];
    [self.switchStatusImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.colorBackImageView.mas_top).offset(kFragmemtFloat(17.5));
        make.right.equalTo(self.colorBackImageView.mas_right).offset(-kFragmemtFloat(15));
        make.size.mas_equalTo(kSizzleKapadate(50, 24));
    }];
    [self.roomNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(kFragmemtFloat(15));
        make.right.equalTo(self.contentView.mas_right).offset(-kFragmemtFloat(15));
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-kFragmemtFloat(17));
    }];
    [self.deviceNicenameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.roomNameLabel);
        make.bottom.equalTo(self.roomNameLabel.mas_top).offset(-kFragmemtFloat(6));
    }];
}

- (UIImageView *)colorBackImageView {
    if (!_colorBackImageView) {
        _colorBackImageView = [[UIImageView alloc] initWithImage:kImageName(@"base_deviceCollCell_image")];
    }
    return _colorBackImageView;
}

- (UIImageView *)deviceTypeImageView {
    if (!_deviceTypeImageView) {
        _deviceTypeImageView = [[UIImageView alloc] initWithImage:kImageName(@"device_celltype_switch")];
    }
    return _deviceTypeImageView;
}

- (UIImageView *)switchStatusImageView {
    if (!_switchStatusImageView) {
        _switchStatusImageView = [[UIImageView alloc] initWithImage:kImageName(@"device_celltype_off")];
    }
    return _switchStatusImageView;
}

- (UILabel *)roomNameLabel {
    if (!_roomNameLabel) {
        _roomNameLabel = [UILabel initWithTextColor:UIColor.blackColor weight:UIFontWeightMedium size:15];
    }
    return _roomNameLabel;
}

- (UILabel *)deviceNicenameLabel {
    if (!_deviceNicenameLabel) {
        _deviceNicenameLabel = [UILabel initWithTextColor:k_Color_898989 weight:UIFontWeightMedium size:13];
        _deviceNicenameLabel.text = @"设备昵称";
    }
    return _deviceNicenameLabel;
}


@end
